package com.example.blogserver.mq;

import com.example.blogserver.a_utils.MqConstants;
import com.example.blogserver.service.ArticleService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description
 * @descriptionDetail
 * @Author B3300
 * @copyright 摸鱼王胖嘟嘟
 * @Date 2024/3/25 11:39
 */
@Component
public class ArticleListener {

    @Autowired
    private ArticleService articleService;

    /**
     * 监听文章新增或修改的业务
     * @param id 文章id
     */
    @RabbitListener(queues = MqConstants.ARTICLE_INSERT_QUEUE)
    public void listenArticleInsertOrUpdate(Long id) {
        articleService.InsertOrUpdateDocumentById(id);
    }

    /**
     * 监听文章删除的业务
     * @param id 文章id
     */
    @RabbitListener(queues = MqConstants.ARTICLE_DELETE_QUEUE)
    public void listenArticleDelete(Long id) {
        articleService.deleteDocumentById(id);
    }
}
